package cn.hquanheng.java_base.arrayTask;

import java.util.Arrays;

import java.util.Scanner;

public class Shuffle {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int[] numbers = new int[5];
		System.out.println("Please Enter:");
		for (int i = 0; i < numbers.length; i++) {
			numbers[i] = input.nextInt();
		}
		System.out.println(Arrays.toString(numbers));
		shuffle(numbers);
		System.out.println(Arrays.toString(numbers));

	}

	public static void shuffle(int[] numbers) {
		int n = numbers.length;
		int[] nTitle = new int[n];// numbers的随机下标；
		for (int i = 0; i < numbers.length; i++) {// numbers的固定下标
			boolean flag = true;// 表示 i下标具有唯一性
			do {
				nTitle[i] = (int) (Math.random() * n);
				flag = true;
				// 遍历确定随机下标的唯一性
				for (int j = 0; j <= i; j++) {
					if (nTitle[i] == nTitle[j] && i != j) {
						flag = false;// 出现相同
					}
				}
			} while (flag == false);
		}
		System.out.println(Arrays.toString(nTitle));
		// 交换numbers数组值
		int[] numbersArg = new int[n];
		System.arraycopy(numbers, 0, numbersArg, 0, n);
		for (int w = 0; w < n; w++) {
			numbers[w] = numbersArg[nTitle[w]];
		}

	}

}
